package MyServlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Role;
import service.ServiceException;
import service.local.RoleService;

/**
 * Servlet implementation class AddRoleServlet
 */
public class AddRoleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	// @EJB
	// private RoleService rs;
	/**
	 * @see HttpServlet#HttpServlet()
	 */

	public AddRoleServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		InitialContext ic;
		RoleService rs;
		try {
			ic = new InitialContext();
			rs = (RoleService) ic
					.lookup("java:global/jthr-server/jthr-backend-0.0.1-SNAPSHOT/RoleService!service.local.RoleService");
			Role r = new Role("dadada");
			rs.insertRole(r);
		} catch (NamingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.out.println("OK");
		RequestDispatcher rd = request
				.getRequestDispatcher("/add_position.jsp");
		rd.forward(request, response);
	}

	/*
	 * protected void doGet(HttpServletRequest request, HttpServletResponse
	 * response) throws ServletException, IOException {
	 * 
	 * 
	 * Role r = new Role("test"); if(rs == null)
	 * System.out.println("Role Service NULL"); rs.insertRole(r);
	 * response.getWriter().println("MERGEEE INSERTUL"); RequestDispatcher rd =
	 * request.getRequestDispatcher("/add_position.jsp"); rd.forward(request,
	 * response); }
	 */

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
